<template>
  <div>
    <myheader></myheader>
    <br>
    <!--面包屑导航-->
    <Breadcrumb :datas="datas"></Breadcrumb>

    <section class="featured-block text-center">
      <div class="container">

        分类名：<input type="text" v-model="cname">

        <Button v-on:click="submit" style="width: 100px">添加</Button>

      </div>
    </section>
    <myfooter></myfooter>

  </div>
</template>


<script>
  // 组件包含
  import myheader from '@/components/myheader'
  import myfooter from '@/components/myfooter'



  export default {
    data() {
      return {
        //面包屑导航
        datas: [{title: '首页', route: {name: 'index'}}, {title: '添加分类'}],
     cname:'',
      }
    },
    //定义组件
    components: {
      'myheader': myheader,
      'myfooter': myfooter,

    },

    mounted: function () {

    },
    methods: {

      //提交事件
      submit() {

        //  判断用户是否输入
        if (this.cname == '') {
          this.$Message('分类名不能为空')
        }
        //  请求后台接口
        this.axios({
          url: 'http://localhost:8000/addcate/',
          method: 'get',
          params: {'cname': this.cname}
        }).then(res => {
          console.log(res);
          if (res.data.code == 200) {
            this.$Message('添加成功');

          } else {
            this.$Message(res.data.message)
          }
        })
      },
    }
  }


</script>